<template>
  <el-dialog :title="title" v-model="dialogVisible" width="30%">
    <!-- <el-dialog v-model="dialogVisible" title="用户新增" @close="handleClose"> -->
    <el-form :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="出生日期">
        <el-date-picker type="date" placeholder="选择日期" v-model="form.birthday" style="width: 100%"></el-date-picker>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="form.gender">
          <el-radio value="男">男</el-radio>
          <el-radio value="女">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否禁用">
        <el-switch v-model="form.forbidden"></el-switch>
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="form.role" placeholder="请选择用户身份">
          <el-option label="普通用户" value="普通用户"></el-option>
          <el-option label="管理员" value="管理员"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, defineProps, defineEmits, watch } from 'vue';
const props = defineProps({
  dialogVisible: Boolean,
  formData: Object
});
const emit = defineEmits(['update:dialog-visible', 'save']);

const form = ref(props.formData);

const submitForm = () => {
  emit('save', { ...form.value });
  emit('update:dialog-visible', false);
};

const title = ref('用户新增');
// if (props.formData.date) {
//   title.value = '编辑用户';
// }
</script>